namespace Adge.Common
{
    using System;
    using System.Web;

    public class CSRequest
    {
        public static float GetFloat(string strName, float defValue)
        {
            if (CSRequest.GetQueryFloat(strName, defValue) == defValue)
            {
                return CSRequest.GetFormFloat(strName, defValue);
            }
            return CSRequest.GetQueryFloat(strName, defValue);
        }

        public static float GetFormFloat(string strName, float defValue)
        {
            return Utils.StrToFloat(HttpContext.Current.Request.Form[strName], defValue);
        }

        public static int GetFormInt(string strName, int defValue)
        {
            return Utils.StrToInt(HttpContext.Current.Request.Form[strName], defValue);
        }

        public static string GetFormString(string strName)
        {
            if (HttpContext.Current.Request.Form[strName] == null)
            {
                return "";
            }
            return HttpContext.Current.Request.Form[strName];
        }

        public static int GetInt(string strName, int defValue)
        {
            if (CSRequest.GetQueryInt(strName, defValue) == defValue)
            {
                return CSRequest.GetFormInt(strName, defValue);
            }
            return CSRequest.GetQueryInt(strName, defValue);
        }

        public static string GetIP()
        {
            string text1 = string.Empty;
            text1 = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            switch (text1)
            {
                case null:
                case "":
                    text1 = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    break;
            }
            switch (text1)
            {
                case null:
                case "":
                    text1 = HttpContext.Current.Request.UserHostAddress;
                    break;
            }
            switch (text1)
            {
                case null:
                case "":
                    return "0.0.0.0";
            }
            return text1;
        }

        public static string GetPageName()
        {
            string[] textArray1 = HttpContext.Current.Request.Url.AbsolutePath.Split(new char[] { '/' });
            return textArray1[textArray1.Length - 1].ToLower();
        }

        public static float GetQueryFloat(string strName, float defValue)
        {
            return Utils.StrToFloat(HttpContext.Current.Request.QueryString[strName], defValue);
        }

        public static int GetQueryInt(string strName, int defValue)
        {
            return Utils.StrToInt(HttpContext.Current.Request.QueryString[strName], defValue);
        }

        public static string GetQueryString(string strName)
        {
            if (HttpContext.Current.Request.QueryString[strName] == null)
            {
                return "";
            }
            return HttpContext.Current.Request.QueryString[strName];
        }

        public static string GetRawUrl()
        {
            return HttpContext.Current.Request.RawUrl;
        }

        public static string GetServerString(string strName)
        {
            if (HttpContext.Current.Request.ServerVariables[strName] == null)
            {
                return "";
            }
            return HttpContext.Current.Request.ServerVariables[strName].ToString();
        }

        public static string GetString(string strName)
        {
            if ("".Equals(CSRequest.GetQueryString(strName)))
            {
                return CSRequest.GetFormString(strName);
            }
            return CSRequest.GetQueryString(strName);
        }

        public static string GetUrl()
        {
            return HttpContext.Current.Request.Url.ToString();
        }

        public static string GetUrlReferrer()
        {
            return HttpContext.Current.Request.UrlReferrer.ToString();
        }

        public static bool IsBrowserGet()
        {
            string[] textArray1 = new string[] { "ie", "opera", "netscape", "mozilla" };
            string text1 = HttpContext.Current.Request.Browser.Type.ToLower();
            for (int num1 = 0; num1 < textArray1.Length; num1++)
            {
                if (text1.IndexOf(textArray1[num1]) >= 0)
                {
                    return true;
                }
            }
            return false;
        }

        public static bool IsGet()
        {
            return HttpContext.Current.Request.HttpMethod.Equals("GET");
        }

        public static bool IsPost()
        {
            return HttpContext.Current.Request.HttpMethod.Equals("POST");
        }

        public static bool IsSearchEnginesGet()
        {
            string[] textArray1 = new string[] { "google", "yahoo", "msn", "baidu", "sogou", "sohu", "sina", "163", "lycos", "tom" };
            string text1 = HttpContext.Current.Request.UrlReferrer.ToString().ToLower();
            for (int num1 = 0; num1 < textArray1.Length; num1++)
            {
                if (text1.IndexOf(textArray1[num1]) >= 0)
                {
                    return true;
                }
            }
            return false;
        }

        public static void SaveRequestFile(string path)
        {
            if (HttpContext.Current.Request.Files.Count > 0)
            {
                HttpContext.Current.Request.Files[0].SaveAs(path);
            }
        }

    }
}

